var cluster = require('cluster')
var os = require('os')
var numCPUs = os.cpus().length
function fibo (n) {
  return n > 1 ? fibo(n - 1) + fibo(n - 2) : 1
}
console.time(`${numCPUs} cluster`)
if (cluster.isMaster) {
  // Fork workers.
  for (var i = 0; i < numCPUs; i++) {
    cluster.fork()
  }
  var j = numCPUs
  cluster.on('exit', function (worker, code, signal) {
    if (!--j) {
      console.timeEnd(`${numCPUs} cluster`)
      process.exit(0)
    }
  })
} else {
  console.log(fibo(40))
  process.exit(0)
}
